function goSort() {
    var standard = $("#standard").val();
    var data = $("#data").val();
    if (standard) {
        var standardArr = standard.split("\n");
        var standardArrTrim = [];
        var standardEmptyCount = 0;
        for (var i = standardArr.length; i > 0; i--) {
            if (standardArr[i - 1].trim() == "") {
                standardEmptyCount++;
            } else {
                break;
            }
        }
        $("#standardBadge").html(standardArr.length - standardEmptyCount);
        $.each(standardArr, function (i, item) {
            if (i < standardArr.length - standardEmptyCount) {
                standardArrTrim.push(item.trim());
            }
        });
        if (data) {
            var dataArr = data.split("\n");
            var dataEmptyCount = 0;
            var dataDict = [];
            for (var i = dataArr.length; i > 0; i--) {
                if (dataArr[i - 1].trim() == "") {
                    dataEmptyCount++;
                } else {
                    break;
                }
            }
            $("#dataBadge").html(dataArr.length - dataEmptyCount);
            $.each(dataArr, function (i, item) {
                if (i < dataArr.length - dataEmptyCount) {
                    var itemArr = item.split(" ");
                    //如果用空格分割无效,尝试用tab分割
                    if (itemArr == item) {
                        itemArr = item.split("\t");
                    }
                    dataDict[itemArr[0]] = item;
                }
            });
        }
        if (standard && data) {
            var result = "";
            var resultArr = [];
            var resultCount = 0;
            var resultAMinusB = "";
            var resultAMinusBCount = 0;

            $.each(standardArrTrim, function (i, item) {
                if (dataDict[item]) {
                    result += dataDict[item] + "\n";
                    resultArr[item] = true;
                    resultCount++;
                } else {
                    result += "\n";
                    resultAMinusB += item + "\n";
                    resultAMinusBCount++;
                }
            });

            var resultBMinusA = "";
            var resultBMinusACount = 0;
            $.each(dataArr, function (i, item) {
                if (i < dataArr.length - dataEmptyCount) {
                    var itemArr = item.split(" ");
                    //如果用空格分割无效,尝试用tab分割
                    if (itemArr == item) {
                        itemArr = item.split("\t");
                    }
                    if (!resultArr[itemArr[0]]) {
                        resultBMinusA += item + "\n";
                        resultBMinusACount++;
                    }
                }
            });

            $("#sortBadge").html(resultCount);
            $("#aMinusBBadge").html(resultAMinusBCount);
            $("#bMinusABadge").html(resultBMinusACount);
            $("#resultSort").val(result);
            $("#resultAMinusB").val(resultAMinusB);
            $("#resultBMinusA").val(resultBMinusA);
        }
    }
}

function showYou() {
    $("#standard").val("张三\n李四\n王五\n赵六");
    $("#data").val("王五\t99\n张三\t88\n赵六\t98\n孙七\t66");
    goSort();
}

function clearAll() {
    $("#standard").val("");
    $("#data").val("");
    $("#resultSort").val("");
    $("#resultAMinusB").val("");
    $("#resultBMinusA").val("");
    $(".badge").html("0");
}